home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Program Name: Stiletto */
- /* */
- /* File Name: Stiletto.c */
- /* */
- /* © Apple Computer, Inc. 1991-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1991-06-30 Chris Halim Original version */
- /* 1995-06-26 Jaakko Railo Version 2.0 */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #include "Aliases.h"
- #include "Desk.h"
- #include "DiskInit.h"
- #include "FCntl.h"
- #include "Gestalt.h"
- #include "Resources.h"
- #include "SegLoad.h"
- #include "string.h"
- #include "Strings.h"
- #include "ToolUtils.h"
- #include "Traps.h"
-
- #include "Telephones.h"
-
- #include "About.h"
- #include "CAHandlers.h"
- #include "Constants.h"
- #include "DNHandlers.h"
- #include "Init.h"
- #include "LogWindow.h"
- #include "ModuleWindow.h"
- #include "Preferences.h"
- #include "Stiletto.h"
- #include "TermWindow.h"
- #include "TestModule.h"
- #include "Utilities.h"
-
- /****************************************** DEFINITIONS *****************************************/
-
- static AEHandlerStructure keywordsToInstall[] = {
- { kCoreEventClass, kAEOpenApplication, (ProcPtr) DoAEOpenApplication },
- { kCoreEventClass, kAEOpenDocuments, (ProcPtr) DoAEOpenDocuments },
- { kCoreEventClass, kAEPrintDocuments, (ProcPtr) DoAEPrintDocuments },
- { kCoreEventClass, kAEQuitApplication, (ProcPtr) DoAEQuitApplication }
- };
-
- /****************************************** PROTOTYPES ******************************************/
-
- /******************************************** GLOBALS *******************************************/
-
- Boolean gInBackground = false;
- Boolean gQuit = false;
-
- LogWindowPtr gLogWindow = nil;
- TelWindowPtr gTelWindow = nil;
- ModuleWindowPtr gModuleWindow = nil;
-
- TELCAHandle gAvailableCA = nil;
-
- extern TelephoneCAMsgUPP gAllCAMsgsHandlerUPP;
- extern TelephoneDNMsgUPP gAllDNMsgsHandlerUPP;
- extern TelephoneTermMsgUPP gAllTermMsgsHandlerUPP;
-
- extern TelephoneTermMsgUPP gTermMsgHandlerUPP;
-
- #ifdef __powerc
- QDGlobals qd;
- #endif
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- /**
- ** This routine is part of the MPW runtime library. We need an external reference
- ** to it, so that we can unload its segment (%A5Init) early in the program.
- **/
-
- extern void _DataInit();
-
-
- #pragma segment Main
- void Terminate (void)
- {
- //
- // If we have any open document that needs to be saved to disk,
- // this is the place to ask if user wants to save open files.
- // IMPORTANT : if cancel is chosen, DO NOT quit !!!
- //
-
- TELHandle termHand;
- OSErr errCode;
-
- SaveWinLocToPref ((WindowPtr) gLogWindow, rLogWindRECT);
- SaveWinLocToPref ((WindowPtr) gTelWindow, rTelWindRECT);
- SaveWinLocToPref ((WindowPtr) gModuleWindow, rModuleWindRECT);
-
- termHand = gTelWindow->fTELHandle;
-
- DisposeTelWindow (gTelWindow);
-
- if ((errCode = TELClrTermMsgHand (termHand, gTermMsgHandlerUPP)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELClrTermMsgHand failed : %d", errCode);
-
- if ((errCode = TELCloseTerm (termHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELCloseTerm failed : %d", errCode);
-
- if ((errCode = TELDispose (termHand)) != noErr)
- PutCLine (gLogWindow, kErrorColor, "### TELDispose failed : %d", errCode);
-
- DisposeModuleWindow (gModuleWindow);
-
- gQuit = true;
- }
-
-
- #pragma segment Initialize
- void InitializedAppleEvents (void)
- {
- OSErr errCode;
- short i;
- AEEventHandlerUPP theAEEventHandlerUPP;
-
- for (i = 0; i < (sizeof(keywordsToInstall) / sizeof(AEHandlerStructure)); ++i) {
- theAEEventHandlerUPP = NewAEEventHandlerProc (keywordsToInstall[i].theHandler);
- if (theAEEventHandlerUPP != NULL) {
- errCode = AEInstallEventHandler(
- keywordsToInstall[i].theEventClass, /* What class to install. */
- keywordsToInstall[i].theEventID, /* Keywords to install. */
- theAEEventHandlerUPP, /* The AppleEvent handler. */
- 0L, /* Unused refcon. */
- false /* Only for our app. */
- );
-
- if (errCode)
- PutLine (gLogWindow, "### AEInstallEventHandler fails : ", errCode);
- }
- else
- PutLine (gLogWindow, "### NewAEEventHandlerProc failed : ", MemError());
- }
- }
-
-
- #pragma segment Main
- void AdjustMenus (void)
- {
- MenuHandle aMenu1, aMenu2;
- long windRefCon = GetWRefCon (FrontWindow ());
- short item;
-
- aMenu1 = GetMHandle (rFileMenu);
- if (FrontWindow())
- EnableItem (aMenu1, iClose);
- else
- DisableItem (aMenu1, iClose);
-
- aMenu1 = GetMHandle (rEditMenu); // At this stage of the program, we are
- DisableItem (aMenu1, iUndo); // not implementing edit capabilities.
- DisableItem (aMenu1, iCut);
- DisableItem (aMenu1, iCopy);
- DisableItem (aMenu1, iPaste);
- DisableItem (aMenu1, iClear);
-
- aMenu1 = GetMHandle (rInfoMenu);
- for (item = iDumpCAState; item <= iDumpTermEvents; ++ item)
- DisableItem (aMenu1, item);
-
- aMenu2 = GetMHandle (rHandlerMenu);
- for (item = iInstallAllCA; item <= iRemoveAllTerm; ++ item)
- DisableItem (aMenu2, item);
-
- switch (windRefCon) {
- case rCAWIND :
- EnableItem (aMenu1, iDumpCAState);
- EnableItem (aMenu1, iDumpCAInfo);
- EnableItem (aMenu1, iDumpCAEvents);
- EnableItem (aMenu1, iDumpCAFlags);
- break;
-
- case rDNWIND :
- EnableItem (aMenu1, iDumpDNInfo);
- EnableItem (aMenu1, iDumpDNEvents);
- EnableItem (aMenu1, iDumpDNFlags);
-
- EnableItem (aMenu2, iInstallAllCA);
- EnableItem (aMenu2, iRemoveAllCA);
-
- EnableItem (aMenu2, iInstallAllDN);
- EnableItem (aMenu2, iRemoveAllDN);
- break;
-
- case rTelWIND :
- EnableItem (aMenu1, iDumpTermInfo);
- EnableItem (aMenu1, iDumpTermEvents);
-
- EnableItem (aMenu2, iInstallAllTerm);
- EnableItem (aMenu2, iRemoveAllTerm);
- break;
- }
- }
-
-
- #pragma segment Main
- void LoopTheLoop (void)
- {
- EventRecord theEvent;
- RgnHandle cursorRgn;
- Boolean gotEvent;
-
- cursorRgn = NewRgn (); // We don't have any specialized cursor in this
- // app. so pass NIL to WaitNextEvent ().
- while (!gQuit) // Keep checking the event queue until user
- { // wants to quit.
-
- gotEvent = WaitNextEvent (everyEvent, &theEvent, SleepVal(), cursorRgn);
-
- if (! IsHandledByModuleWindow (gModuleWindow, &theEvent))
- {
- if (! IsHandledByTelWindow (gTelWindow, &theEvent))
- {
- if (! IsHandledByLogWindow (gLogWindow, &theEvent))
- {
- if (gotEvent)
- HandleEvent (&theEvent);
- else
- DoIdle ();
- }
- }
- }
- }
- }
-
-
- #pragma segment Main
- unsigned long SleepVal(void)
- {
- unsigned long sleep;
- const long kSleepTime = 0x00; // we want to be called as often as possible
-
- sleep = kSleepTime; // default value for sleep
- if ((!gInBackground))
- {
- sleep = GetCaretTime();
- }
- return sleep;
- }
-
-
- #pragma segment Main
- void DoIdle (void)
- {
- }
-
-
- #pragma segment Main
- void HandleEvent(const EventRecord *theEvent)
- {
- short err;
- char key;
- Point aPoint;
-
- switch ( theEvent->what ) {
- case nullEvent :
- DoIdle ();
- break;
-
- case mouseDown :
- DoMouseDown (theEvent);
- break;
-
- case mouseUp:
- DoMouseUp (theEvent);
- break;
-
- case keyDown:
- case autoKey:
- key = theEvent->message & charCodeMask;
- if ( theEvent->modifiers & cmdKey ) { // Command key is down
- if ( theEvent->what == keyDown ) {
- AdjustMenus();
- DoMenuCommand(MenuKey(key), theEvent->modifiers);
- }
- } else {
- switch (key) {
- case 'c' :
- PutLine (gLogWindow, "Tyger! Tyger! burning bright");
- PutLine (gLogWindow, "In the forests of the night,");
- PutLine (gLogWindow, "What immortal hand or eye");
- PutLine (gLogWindow, "Could frame thy fearful symmetry?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, "In what distant deeps or skies");
- PutLine (gLogWindow, "Burnt the fire of thine eyes?");
- PutLine (gLogWindow, "On what wings dare he aspire?");
- PutLine (gLogWindow, "What the hand, dare seize the fire?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, "And what shoulder, & what art,");
- PutLine (gLogWindow, "Could twist the sinews of thy heart?");
- PutLine (gLogWindow, "And when thy heart began to beat,");
- PutLine (gLogWindow, "What dread hand? & what dread feet?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, "What the hammer? what the chain?");
- PutLine (gLogWindow, "In what furnace was thy brain?");
- PutLine (gLogWindow, "What the anvil? what dread grasp");
- PutLine (gLogWindow, "Dare its deadly terrors clasp?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, "When the stars threw down their spears,");
- PutLine (gLogWindow, "And water'd heaven with their tears,");
- PutLine (gLogWindow, "Did he smile his work to see?");
- PutLine (gLogWindow, "Did he who made the Lamb make thee?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, "Tyger! Tyger! burning bright");
- PutLine (gLogWindow, "In the forests of the night,");
- PutLine (gLogWindow, "What immortal hand or eye");
- PutLine (gLogWindow, "Dare frame thy fearful symmetry?");
- PutLine (gLogWindow, "");
- PutLine (gLogWindow, " William Blake, 1794");
- PutLine (gLogWindow, "");
- break;
- }
- }
- break;
-
- case activateEvt:
- DoActivate ((WindowPtr) theEvent->message, (theEvent->modifiers & activeFlag) != 0);
- break;
-
- case updateEvt:
- DoUpdate (theEvent);
- break;
-
- case osEvt:
- DoOSEvent (theEvent);
- break;
-
- case kHighLevelEvent:
- DoHighLevelEvent (theEvent);
- break;
-
- case diskEvt:
- // Put this here just in case the user inserts an unformated disk.
- if ( HiWord(theEvent->message) != noErr ) {
- SetPt(&aPoint, kDILeft, kDITop); // TopLeft of DI dialog.
- err = DIBadMount(aPoint, theEvent->message);
- }
- break;
- }
- }
-
-
- #pragma segment Main
- void DoMouseDown (const EventRecord *theEvent)
- {
- short part;
- WindowPtr theWindow;
- long menuResult;
-
- part = FindWindow(theEvent->where, &theWindow);
- switch ( part ) {
- case inMenuBar:
- AdjustMenus();
- if (menuResult = MenuSelect(theEvent->where))
- DoMenuCommand(menuResult, theEvent->modifiers);
- else
- DoDisabledMenu();
- break;
-
- case inSysWindow:
- SystemClick(theEvent, theWindow);
- break;
-
- case inContent:
- if ( theWindow != FrontWindow() ) {
- SelectWindow(theWindow);
- } else
- DoContentClick (theWindow, theEvent);
- break;
-
- case inDrag: // pass screenBits.bounds to get all gDevices
- if (!(theEvent->modifiers & cmdKey)) // if command key isn't down
- SelectWindow (theWindow);
-
- DragWindow(theWindow, theEvent->where, &qd.screenBits.bounds);
- break;
-
- case inGoAway:
- if ( TrackGoAway(theWindow, theEvent->where) )
- HideWindow (theWindow);
- break;
-
- case inGrow:
- DoGrowWindow (theWindow, theEvent);
- break;
-
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox (theWindow, theEvent->where, part) )
- DoZoomWindow (theWindow, part);
- break;
- }
- }
-
-
- #pragma segment Main
- void DoMouseUp (const EventRecord *theEvent)
- {
- #pragma unused (theEvent)
- }
-
-
- #pragma segment Main
- void DoActivate (WindowPtr theWindow, Boolean becomingActive)
- {
- #pragma unused (theWindow, becomingActive)
- }
-
-
- #pragma segment Main
- void DoUpdate (const EventRecord *theEvent)
- {
- WindowPtr theWindow = (WindowPtr) theEvent->message;
-
- BeginUpdate(theWindow);
- if ( ! EmptyRgn(theWindow->visRgn) )
- {
- }
- EndUpdate(theWindow);
- }
-
-
- #pragma segment Main
- void DoOSEvent (const EventRecord *theEvent)
- {
- Boolean doConvert;
- unsigned char evType;
-
- evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
- switch (evType) { // The high byte of message is the type of event.
- case mouseMovedMessage :
- DoIdle();
- break;
-
- case suspendResumeMessage :
- doConvert = (theEvent->message & convertClipboardFlag) != 0;
- gInBackground = (theEvent->message & resumeFlag) == 0;
-
- if (gInBackground)
- DoSuspend (doConvert);
- else DoResume (doConvert);
- break;
- }
- }
-
-
- #pragma segment Main
- void DoSuspend(Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- DoActivate (FrontWindow(), false);
- }
-
-
- #pragma segment Main
- void DoResume(Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- InitCursor ();
- DoActivate (FrontWindow(), true);
- }
-
-
- #pragma segment Main
- void DoHighLevelEvent (const EventRecord *theEvent)
- {
- OSErr errCode = noErr;
-
- switch (theEvent->message) {
- default :
- errCode = AEProcessAppleEvent (theEvent);
- }
- }
-
-
- #pragma segment Main
- OSErr GotRequiredParams (const AppleEvent * theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr errCode = noErr;
-
- errCode = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr, typeWildCard,
- &returnedType, nil, 0, &actualSize);
-
- if (errCode == errAEDescNotFound)
- errCode = noErr;
- else if (errCode == noErr)
- errCode = errAEEventNotHandled;
-
- return (errCode);
- }
-
-
- #pragma segment Main
- pascal OSErr DoAEOpenApplication (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
-
- OSErr errCode = noErr;
-
- if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
- DoNew ();
-
- return (errCode);
- }
-
-
- #pragma segment Main
- pascal OSErr DoAEOpenDocuments (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
-
- OSErr errCode = noErr;
- FSSpec fileSpec;
- AEDescList docList;
- long index, itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- errCode = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
- if (errCode == noErr)
- {
- if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
- {
- (void) AECountItems (&docList, &itemsInList);
-
- for (index = 1; index <= itemsInList; ++index)
- {
- errCode = AEGetNthPtr (&docList, index, typeFSS, &keywd, &returnedType,
- (Ptr) &fileSpec, sizeof(fileSpec), &actualSize);
-
- if (errCode == noErr)
- OpenFile (&fileSpec);
- else
- PutLine (gLogWindow, "### AEGetNthPtr fails : %d", errCode);
- }
- }
- }
-
- (void) AEDisposeDesc (&docList);
-
- return (errCode);
- }
-
-
- #pragma segment Main
- pascal OSErr DoAEPrintDocuments (const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
-
- OSErr errCode = noErr;
- FSSpec fileSpec;
- AEDescList docList;
- long index, itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- errCode = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList);
- if (errCode == noErr)
- {
- if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
- {
- (void) AECountItems (&docList, &itemsInList);
-
- for (index = 1; index <= itemsInList; ++index)
- {
- errCode = AEGetNthPtr (&docList, index, typeFSS, &keywd, &returnedType,
- (Ptr) &fileSpec, sizeof(fileSpec), &actualSize);
-
- if (errCode == noErr)
- PrintFile (&fileSpec);
- else
- PutLine (gLogWindow, "### AEGetNthPtr fails : %d", errCode);
- }
- }
- }
-
- (void) AEDisposeDesc (&docList);
-
- return (errCode);
- }
-
-
- #pragma segment Main
- pascal OSErr DoAEQuitApplication(const AppleEvent *theAppleEvent, const AppleEvent *reply, long refcon)
- {
- #pragma unused (reply, refcon)
-
- OSErr errCode;
-
- if ((errCode = GotRequiredParams (theAppleEvent)) == noErr)
- {
- if (CancelTerminate ())
- errCode = userCanceledErr;
- }
-
- return (errCode);
- }
-
-
- #pragma segment Main
- void DoGrowWindow(WindowPtr theWindow, const EventRecord * theEvent)
- {
- long growResult;
- Rect growRect;
- WindowPtr savedPort;
-
- growRect = qd.screenBits.bounds;
- growRect.left = kMinWindowWidth;
- growRect.top = kMinWindowHeight;
-
- growResult = GrowWindow(theWindow, theEvent->where, &growRect);
-
- if ( growResult != 0 ) {
-
- SizeWindow (theWindow, LoWord(growResult), HiWord(growResult), true);
-
- GetPort (&savedPort);
- SetPort (theWindow);
- InvalRect (&theWindow->portRect);
- SetPort (savedPort);
- }
- }
-
-
- #pragma segment Main
- void DoZoomWindow(WindowPtr theWindow, short part)
- {
- #pragma unused (theWindow, part)
- }
-
-
- #pragma segment Main
- void DoContentClick (WindowPtr theWindow, const EventRecord * theEvent)
- {
- #pragma unused (theWindow, theEvent)
- }
-
-
- #pragma segment Main
- void DoDisabledMenu(void)
- {
- const long * kMenuDisable = (long *) 0xB54;
-
- long menuResult;
- short menuID; // resource ID of the selected menu
- short menuItem; // item number of the selected menu
-
- if (TrapAvailable (_MenuChoice))
- menuResult = MenuChoice();
- else
- menuResult = *(kMenuDisable);
-
- menuID = HiWord(menuResult);
- menuItem = LoWord(menuResult);
-
- HiliteMenu (menuID); // This explicit call is necessary since menu was
- // already unhilited by the system at this point.
- switch ( menuID ) {
- }
- HiliteMenu (0);
- }
-
-
- #pragma segment Main
- void DoMenuCommand(long menuResult, short modifiers)
- {
- short menuID; // resource ID of the selected menu
- short menuItem; // item number of the selected menu
- Str255 daName;
- short daRefNum;
- Boolean handledByDA;
- WindowPtr tWindow;
- Boolean wasHandled = false;
-
- menuID = HiWord(menuResult);
- menuItem = LoWord(menuResult);
-
- if (gTelWindow && gTelWindow->fTELHandle)
- wasHandled = TELMenu (gTelWindow->fTELHandle, menuID, menuItem);
-
- if (!wasHandled)
- {
- switch ( menuID ) {
- case rAppleMenu:
- switch ( menuItem ) {
- case iAbout:
- DoAbout ();
- break;
-
- default: // Let system handle all Apple Menu Items
- GetItem(GetMHandle(rAppleMenu), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
-
- case rFileMenu:
- switch ( menuItem ) {
- case iClose:
- if (tWindow = FrontWindow())
- HideWindow (tWindow);
- break;
-
- case iQuit:
- if (CancelTerminate ())
- ;
- break;
- }
- break;
-
- case rEditMenu:
- handledByDA = SystemEdit(menuItem - 1);
- break;
-
- case rWindowMenu:
- switch ( menuItem ) {
- case iShowTerm :
- ShowWindow ((WindowPtr) gTelWindow);
- SelectWindow ((WindowPtr) gTelWindow);
- break;
-
- case iShowModule :
- ShowWindow ((WindowPtr) gModuleWindow);
- SelectWindow ((WindowPtr) gModuleWindow);
- break;
-
- case iShowLog :
- ShowWindow ((WindowPtr) gLogWindow);
- SelectWindow ((WindowPtr) gLogWindow);
- break;
-
- case iClearLog :
- ClearLogWindow (gLogWindow);
- break;
- }
- break;
-
- case rTestMenu:
- switch ( menuItem ) {
- case iAnyModule :
- ExecuteAnyModule ();
- break;
-
- case iChangeDir :
- if (GetNewTestDirAlias (gModuleWindow))
- (void) CreateNameList (gModuleWindow);
- break;
- }
- break;
-
- case rFeatureMenu:
- HandleFeatureMenu (gTelWindow, menuID, menuItem, modifiers);
- break;
-
- case rInfoMenu:
- HandleInfoMenu (menuID, menuItem);
- break;
-
- case rHandlerMenu:
- HandleHandlerMenu (menuID, menuItem);
- break;
- }
- }
- HiliteMenu(0); // Unhighlight what MenuSelect (or MenuKey) hilited.
- }
-
-
- #pragma segment Main
- void HandleInfoMenu (short menuID, short menuItem)
- {
- #pragma unused (menuID)
-
- OSErr errCode = noErr;
- WindowPtr theWindow = FrontWindow ();
-
- switch (menuItem) {
- case iDumpCAState :
- DumpCAState (((CAWindowPtr) theWindow)->fCAHandle);
- break;
-
- case iDumpCAInfo :
- DumpCAInfo (((CAWindowPtr) theWindow)->fCAHandle);
- break;
-
- case iDumpCAEvents :
- DumpCAEvents ((*((CAWindowPtr) theWindow)->fCAHandle)->hTELDN);
- break;
-
- case iDumpCAFlags :
- DumpCAFlags (((CAWindowPtr) theWindow)->fCAHandle);
- break;
-
- case iDumpDNInfo :
- DumpDNInfo (((DNWindowPtr) theWindow)->fDNHandle);
- break;
-
- case iDumpDNEvents :
- DumpDNEvents (((DNWindowPtr) theWindow)->fDNHandle);
- break;
-
- case iDumpDNFlags :
- DumpDNFlags (((DNWindowPtr) theWindow)->fDNHandle);
- break;
-
- case iDumpTermInfo :
- DumpTermInfo (gTelWindow);
- break;
-
- case iDumpTermEvents:
- DumpTermEvents (gTelWindow);
- break;
- }
- }
-
-
- #pragma segment Main
- void HandleHandlerMenu (short menuID, short menuItem)
- {
- #pragma unused (menuID)
-
- OSErr errCode = noErr;
- WindowPtr theWindow = FrontWindow ();
-
- switch (menuItem) {
- case iInstallAllCA :
- errCode = TELCAMsgHand (((DNWindowPtr) theWindow)->fDNHandle, telAllCAMsgs, gAllCAMsgsHandlerUPP, SetCurrentA5());
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllCAMsgsHandlerUPP is installed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELCAMsgHand fails : %d", errCode);
- break;
-
- case iRemoveAllCA :
- errCode = TELClrCAMsgHand (((DNWindowPtr) theWindow)->fDNHandle, gAllCAMsgsHandlerUPP);
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllCAMsgsHandlerUPP is removed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
- break;
-
- case iInstallAllDN :
- errCode = TELDNMsgHand (((DNWindowPtr) theWindow)->fDNHandle, false, telAllDNMsgs, gAllDNMsgsHandlerUPP, SetCurrentA5());
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllDNMsgsHandlerUPP is installed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELDNMsgHand fails : %d", errCode);
- break;
-
- case iRemoveAllDN :
- errCode = TELClrDNMsgHand (((DNWindowPtr) theWindow)->fDNHandle, gAllDNMsgsHandlerUPP);
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllDNMsgsHandlerUPP is removed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELClrDNMsgHand fails : %d", errCode);
- break;
-
- case iInstallAllTerm:
- errCode = TELTermMsgHand (((TelWindowPtr) theWindow)->fTELHandle, telAllTermMsgs, gAllTermMsgsHandlerUPP, SetCurrentA5());
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllTermMsgsHandlerUPP is installed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELTermMsgHand fails : %d", errCode);
- break;
-
- case iRemoveAllTerm :
- errCode = TELClrTermMsgHand (((TelWindowPtr) theWindow)->fTELHandle, gAllTermMsgsHandlerUPP);
- if (errCode == noErr)
- PutLine (gLogWindow, "gAllTermMsgsHandlerUPP is removed");
- else
- PutCLine (gLogWindow, kErrorColor, "### TELClrTermMsgHand fails : %d", errCode);
- break;
- }
- }
-
-
- #pragma segment Main
- Boolean WrongEnvironment (void)
- {
- long response;
- OSErr errCode = Gestalt (gestaltSystemVersion, &response);
-
- if (errCode != noErr) {
- AlertUser ("\pGestalt fails !", errCode);
- return (true);
- }
-
- if (response < 0x700) {
- AlertUser ("\pStiletto requires system 7 or later.", response);
- return (true);
- }
-
- return (false);
- }
-
-
- #pragma segment Main
- void DoNew (void)
- {
- }
-
-
- #pragma segment Main
- void OpenFile (FSSpecPtr theFile)
- {
- ExecuteModule (theFile);
- }
-
-
- #pragma segment Main
- void PrintFile (FSSpecPtr theFile)
- {
- #pragma unused (theFile)
- }
-
-
- #pragma segment Main
- Boolean CancelTerminate (void)
- {
- /**
- ** Check if user intends to cancel quiting.
- ** If quiting is no longer desired, return true
- ** else call Terminate() to do some cleanup & return false.
- **/
-
- Terminate ();
-
- return (false);
- }
-
-
- #pragma segment Main
- main ()
- {
- Rect logWindowRect;
- Rect telWindowRect;
- Rect moduleWindowRect;
-
- UnloadSeg ((Ptr) _DataInit); // Don't need this any more (UnloadSeg unsupported on PowerPC)
-
- MaxApplZone(); // Ask for all the memory allowed for this app.
-
- MoreMasters(); // We hate memory fragmentation, so make sure
- MoreMasters(); // we have enough master pointers.
- MoreMasters();
- MoreMasters();
-
- GetWinLocFromPref (&logWindowRect, rLogWindRECT);
- GetWinLocFromPref (&telWindowRect, rTelWindRECT);
- GetWinLocFromPref (&moduleWindowRect, rModuleWindRECT);
-
- if (Initialize () == noErr) // Initialize Mac managers and display the menu bar.
- {
- if (! WrongEnvironment ())
- {
- if (CreateLogWindow (&gLogWindow, &logWindowRect) == noErr)
- {
-
- #ifdef __powerc
- PutLine (gLogWindow, "Running in PPC native mode");
- #else
- PutLine (gLogWindow, "Running in 68K native mode");
- #endif
-
- if (InitCTBManagers () == noErr)
- {
- if (CreateModuleWindow (&gModuleWindow, &moduleWindowRect) == noErr)
- {
- if (CreateTelWindow (&gTelWindow, &telWindowRect, nil) == noErr)
- {
- UnloadSeg ((Ptr) Initialize);
-
- InitializedAppleEvents ();
-
- LoopTheLoop (); // Off we go into the loop of doom.
- }
- }
- }
- }
- }
- }
- }
-